﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlDoc = HtmlAgilityPack.HtmlDocument;
using WebFunctions;
using Newtonsoft.Json;
using System.IO;
using System.Windows.Forms;

namespace AutoIndustryFiles
{
    class fanucScraper:FileLinksScraper2
    {
        public fanucScraper()
        {
            this.MainPage = "http://www.fanuc.co.jp/en/product/catalog/index.html";
            this.CompanyName = "FANUC";
            this.CompanyUrl = "http://www.fanuc.co.jp/en/product/catalog/index.html";
            this.ColumnName = "首页 > Products";
            //this.ReviseXPath += new OnReviseXPath(FuJiScraper_ReviseXPath);            
        }

        public override void GenerateAllLinks(string param)
        {
            string catalog = "";

            string html = File.ReadAllText(@"D:\外包项目\自动化资料下载\Output\fanuc\fanuc.htm", Encoding.GetEncoding("UTF-8"));

            HtmlDoc doc = new HtmlDoc();
            doc.LoadHtml(html);

            HtmlAgilityPack.HtmlNodeCollection hnc = doc.DocumentNode.SelectNodes(@"//table[@class=""small_char""]//tr[position()>1]");

            foreach (HtmlAgilityPack.HtmlNode node in hnc)
            {
                if (node.GetAttributeValue("class", "") == "bluecell3")
                {
                    //分类
                    catalog = node.InnerText.Trim();
                    continue;
                }
                else if (string.IsNullOrEmpty(node.InnerText.Trim()))
                    continue;

                FileLinks.Add(new FileLink(
                    FileLinks.Count.ToString(),
                    FormatUrl(node.SelectSingleNode("td[1]/a").GetAttributeValue("href", ""), "http://www.fanuc.co.jp/en/product/catalog"),
                    node.SelectSingleNode("td[1]/a").InnerText.Trim() + "(" + node.SelectSingleNode("td[2]").InnerText.Trim() + ")",
                    catalog + "->" + node.SelectSingleNode("td[1]/a").InnerText.Trim(),
                    true,
                    "样本",
                    node.SelectSingleNode("td[5]").InnerText.Trim()));
            }
        }
    }
}
